-
Notifications
You must be signed in to change notification settings - Fork 61
Add status_message_with_fallback GH#105,#114 #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Thanks @robrwo. I see a merge conflict. Maybe you need to pull some commits into your branch? |
Hi @robrwo , I will write a -hopefully- better approach for this problem space than the new 'default go to' function you introduced. See the issue #114, where I suggest the introduction of This will make things more explicit, rather than introducing a potentially default go to function that will always come with some message string. Status Codes are super fundamental stuff, you should not just skip but be fully aware that there is something going wrong with whatever passed into it. With a simple default function, one would not even know that somebody passed rubbish, Being explicit gives you the chance to issue warnings. |
…-Message into rrwo/status-message-fallback
@vanHoesel I disagree with you here. The class of a status code indicates roughly what the response is, even if the user agent doesn't know how to handle a specific status code. It is entirely fine to issue any status code between 100 and 599. Just because upstream software (e.g. PSGI or Net::Server) doesn't recognise it, or it's not in an RFC, doesn't mean that there is something wrong. Unfortunately, a lot of modules relay on there being a non-undef/non-blank status message, which means that they either have to implement their own fallbacks for handling unknown status codes, or we can provide something that gives the authors a standard way to handle these gracefully. Adding fake status codes to the hash seems more likely to break things, or require rewriting the is_methods etc. |
sub status_message_with_fallback ($) { | ||
status_message( $_[0] ) | ||
|| ( | ||
is_info( $_[0] ) ? 'OK' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this not "Continue' ?
is_info( $_[0] ) ? 'OK' | |
is_info( $_[0] ) ? 'Continue' |
As mentioned in a new proposal in #114, I'd like to suggest to rename this new function to This way, there is no DWIM default go to method that encourages people to write code that becomes insanely hard to debug. The proposed solution will allow one to write: my $message = status_message($code);
unless ($message) {
$message = status_message_fallback($code);
croak "Status code not understood [$code], assuming ($message)";
} or my $message = status_message($code) || status_message_fallback($code); and my $message = status_message_fallback(200) or die; will just do that |
} | ||
|
||
is(status_message_with_fallback(0), undef); | ||
is(status_message_with_fallback(199), "OK"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Continue
?
is(status_message_with_fallback(199), "OK"); | |
is(status_message_with_fallback(199), "Continue"); |
@vanHoesel, if we merge your branch into this one, is this ready to be merged into master? (Aside from the merge conflict?) |
@oalders , I will need to have a look again, myself. A good thing to clean up stale issues and merge request. Let me get back to this |
Please help me reason about the behaviour of Once those are agreed upon, I can make a final merge request. |
It's been a couple of years, and if I recall, there was some disagreement w.r.t. requested changes. I'll revisit this in the next few days, when I have the time. |
No description provided.